package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICompanyService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.company.CompanyCreateValidate;
import com.mdd.admin.validate.company.CompanySearchValidate;
import com.mdd.admin.validate.company.CompanyUpdateValidate;
import com.mdd.admin.vo.company.CompanyDetailVo;
import com.mdd.admin.vo.company.CompanyListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/company")
@Api(tags = "商务合作管理")
public class CompanyController {

    @Resource
    ICompanyService iCompanyService;

    @GetMapping("/list")
    @ApiOperation(value="商务合作列表")
    public AjaxResult<PageResult<CompanyListedVo>> list(@Validated PageValidate pageValidate,
                                                        @Validated CompanySearchValidate searchValidate) {
        PageResult<CompanyListedVo> list = iCompanyService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="商务合作详情")
    public AjaxResult<CompanyDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CompanyDetailVo detail = iCompanyService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "商务合作新增")
    @PostMapping("/add")
    @ApiOperation(value="商务合作新增")
    public AjaxResult<Object> add(@Validated @RequestBody CompanyCreateValidate createValidate) {
        iCompanyService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "商务合作编辑")
    @PostMapping("/edit")
    @ApiOperation(value="商务合作编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CompanyUpdateValidate updateValidate) {
        iCompanyService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "商务合作删除")
    @PostMapping("/del")
    @ApiOperation(value="商务合作删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCompanyService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
